package com.alks.pad.commom.config;

import com.alks.pad.commom.interceptor.PadAuthenticateInterceptor;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

@Configuration
public class PadInterceptorConfig implements WebMvcConfigurer {
    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        // 这里添加PAD模块拦截器，并设置其拦截规则
        String[] swaggerExcludes=new String[]{"/swagger-ui.html","/swagger-resources/**",
                "/webjars/**","/doc.html","/pad/user/login/**","/pad/user/logout/**","/sdStyle/busMtlDownload"};

        registry.addInterceptor(padAuthenticateInterceptor())
                .addPathPatterns("/pad/**") // 仅拦截以/pad/开头的请求
                .excludePathPatterns(swaggerExcludes); // 排除登录、登出和错误处理等页面
    }

    @Bean
    public PadAuthenticateInterceptor padAuthenticateInterceptor() {
        return new PadAuthenticateInterceptor();
    }
}
